home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / video / security / test.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.4 KB  |  131 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. ;#include <stdlib.h>
  18. #include "video.h"
  19. #include <unistd.h>
  20. #include <gl/gl.h>
  21.  
  22. #ifndef FALSE
  23. #define FALSE                   0
  24. #endif
  25.  
  26. #ifndef TRUE
  27. #define TRUE                    1
  28. #endif
  29.  
  30. #define USAGE \
  31. "Usage: %s  [-g] [-p p] [-f f] [-a a] [ -t t] [-h] \n\
  32. \t-g\tdisplay graphics\n\
  33. \t-p p\tprint message if # frame diffs exceeds <p> \n\
  34. \t-f f\ttotal number of frames grabbed \n\
  35. \t-a a\taccuracy when computing frame diff \n\
  36. \t-t t\tdelay time in hundredths of a sec \n\
  37. \t-h\tthis message \n"
  38.  
  39. int diffBuffer(char *buf1, char *buf2, int x, int y, int acc)
  40. {
  41.   int i, out;
  42.   out = 0;
  43.   for(i=0; i<x*y; i++){
  44.     if((abs((int)(buf1[1] - buf2[1])) > acc) ||
  45.        (abs((int)(buf1[2] - buf2[2])) > acc) ||
  46.        (abs((int)(buf1[3] - buf2[3])) > acc)) out++;
  47.     buf1 += 4; buf2 += 4;
  48.   }
  49.   return out;
  50. }
  51.  
  52. void main(int argc, char **argv)
  53. {
  54. //
  55. // security program:
  56. //  -f number of frames to grab (default 10)
  57. //  -t ticks to delay between grabs (default 100)
  58. //  -a accuracy threshold for compare (default 30)
  59. //  -p print criteria (default 2000)
  60. //  -g run graphics (default no)
  61. //  -h help  
  62. //  
  63.   int accuracy = 30;
  64.   int delay = 100;
  65.   int time = 10;
  66.   int criteria = 2000;
  67.   int hasGrafix = FALSE;
  68.   int i, c, width, height, diffs;
  69.   char *newFrame, *oldFrame;
  70.   char *frame1, *frame2, *frame3;
  71.   VideoIn *videoIn;
  72.  
  73.   while ((c = getopt(argc, argv, "hgt:f:a:p:")) != EOF){
  74.     switch (c){
  75.     case 'a':
  76.       accuracy = atoi(optarg);
  77.       break;
  78.     case 't':
  79.       delay = atoi(optarg);
  80.       break;
  81.     case 'f':
  82.       time = atoi(optarg);
  83.       break;
  84.     case 'p':
  85.       criteria = atoi(optarg);
  86.       break;
  87.     case 'g':
  88.       hasGrafix = TRUE;
  89.       break;
  90.     case 'h':
  91.       printf(USAGE, argv[0]);
  92.       exit(0);
  93.     }
  94.   }
  95.   videoIn = new VideoIn(2);
  96.   if(!videoIn->hasVideo()) {
  97.     fprintf(stderr,"No video input\n");
  98.     exit(1);
  99.   }
  100.   width = videoIn->getWidth();
  101.   height = videoIn->getHeight();
  102.   oldFrame = new char [width*height*4];
  103.   newFrame = new char [width*height*4];
  104.   frame1 = oldFrame; frame2 = newFrame;
  105.   videoIn->getBuffer();
  106.   videoIn->loadFrame(width,height,frame1);
  107.   if(hasGrafix){
  108.     foreground();
  109.     noborder();
  110.     prefsize(width,height);
  111.     long win = winopen("test");
  112.     RGBmode();
  113.     gconfig();
  114. //    pixmode(PM_TTOB,1);
  115.   }
  116.   for(i=0; i<time; i++){
  117.     videoIn->loadFrame(width,height,frame2);
  118.     if(hasGrafix) lrectwrite(0,0,width-1, height-1, (ulong *)frame2);
  119.     diffs = diffBuffer(frame1,frame2,width, height,accuracy);
  120.     printf("There are %d differences\n",diffs);
  121.     if(diffs > criteria){
  122.       printf("There is motion.\n");
  123.     }
  124.     frame3 = frame1; frame1 = frame2; frame2 = frame3;
  125.     sginap(delay);
  126.   }
  127.   videoIn->freeBuffer();
  128.   delete [] newFrame;
  129.   delete [] oldFrame;
  130. }
  131.